package com.yinwq.springcloud.controller;

import com.yinwq.springcloud.entities.CommonResult;
import com.yinwq.springcloud.entities.Payment;
import com.yinwq.springcloud.service.PaymentService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * @author: yinwenqiang@qccr.com
 * @date: Created in 2021/6/7 16:53
 */
@RestController
@Slf4j
public class PaymentController {

    @Resource
    private PaymentService paymentService;

    @Value("${server.port}")
    private String servicePort;

    @PostMapping(value = "/payment/create")
    public CommonResult<Payment> create(@RequestBody Payment payment) {
        int result = paymentService.create(payment);

        if (result > 0) {
            return new CommonResult(200, "成功-port:" + servicePort, result);
        } else {

            return new CommonResult(444, "失败", null);
        }
    }

    @GetMapping(value = "/payment/get/{id}")
    public CommonResult<Payment> get(@PathVariable("id") Long id) {
        Payment payment = paymentService.getPaymentById(id);

        if (payment != null) {
            return new CommonResult(200, "成功-port:" + servicePort, payment);
        } else {

            return new CommonResult(444, "未查到对应记录，id:" + id, null);
        }
    }

    @GetMapping(value = "/payment/lb")
    public String lb(){
        return servicePort;
    }



}
